﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BS_2.VTKClass
{
    class readerFile
    {
        public static ZoneData reader(MemoryStream ms)
        {
            ZoneData zoneData = new ZoneData();
            StreamReader sr = new StreamReader(ms, Encoding.Default);
            String line;
            int incc = 0;
            while ((line = sr.ReadLine()) != null)
            {
                string[] split = line.Split(',');

                if (incc > 0)//将第二行以后的数据添加
                {
                    zoneData.centerX_LS.Add(Convert.ToSingle(split[0]));
                    zoneData.centerY_LS.Add(Convert.ToSingle(split[1]));
                    zoneData.centerZ_LS.Add(Convert.ToSingle(split[2]));

                    List<float> floats = zoneData.varDatas[zoneData.varNames[2]];//由name得到varData返回给list<float>
                    floats.Add(Convert.ToSingle(split[12]));//将split[12]的值add到float
                    List<float> floats1 = zoneData.varDatas[zoneData.varNames[1]];
                    floats1.Add(Convert.ToSingle(split[11]));
                    List<float> floats2 = zoneData.varDatas[zoneData.varNames[0]];
                    floats2.Add(Convert.ToSingle(split[10]));


                }
                else
                {
                    for (int i = 0; i < split.Count(); i++)
                    {

                        if (i >= 10)
                        {
                            String var = split[i];
                            zoneData.varNames.Add(var);
                            zoneData.varDatas.Add(var, new List<float>());
                        }
                    }
                }//incc==0的时候当做名字处理

                if (incc == 1)
                {

                    zoneData.ijk[0] = Convert.ToSingle(split[7]);//将zone的size也即长宽高确定，确定一次即可，后面都一样
                    zoneData.ijk[1] = Convert.ToSingle(split[8]);
                    zoneData.ijk[2] = Convert.ToSingle(split[9]);
                }
                incc += 1;
            }
            return zoneData;
        }
    }
}
